import  request  from '@/utils/request';
    import type { Coupon, CouponListData, CouponQuery } from '@/types/coupon';

    /**
     * 获取优惠券列表
     * @param params
     * @returns
     */
    export const fetchCoupons = (params: CouponQuery) => {
      return request<CouponListData>({
        url: '/v1/coupon',
        method: 'GET',
        data: params,
      });
    };

    /**
     * 获取优惠券详情
     * @param id 优惠券ID
     * @returns
     */
    export const fetchCouponDetail = (id: number) => {
      return request<Coupon>({
        url: `/v1/coupon/${id}`,
        method: 'GET',
      });
    };

    /**
     * 创建优惠券
     * @param data 优惠券信息
     * @returns
     */
    export const createCoupon = (data: Partial<Coupon>) => {
      return request<Coupon>({
        url: '/v1/coupon',
        method: 'POST',
        data,
      });
    };

    /**
     * 更新优惠券信息
     * @param id 优惠券ID
     * @param data 优惠券信息
     * @returns
     */
    export const updateCoupon = (id: number, data: Partial<Coupon>) => {
      return request<Coupon>({
        url: `/v1/coupon/${id}`,
        method: 'PUT',
        data,
      });
    };

    /**
     * 删除优惠券
     * @param id 优惠券ID
     * @returns
     */
    export const deleteCoupon = (id: number) => {
      return request({
        url: `/v1/coupon/${id}`,
        method: 'DELETE',
      });
    };

    // ==================== 优惠券活动管理相关接口 ====================

    /**
     * 获取优惠券活动列表
     * @param params 查询参数
     * @returns
     */
    export const fetchCouponActivities = (params: any) => {
      return request<any>({
        url: '/v1/coupon/activity',
        method: 'GET',
        data: params,
      });
    };

    /**
     * 获取优惠券活动详情
     * @param id 活动ID
     * @returns
     */
    export const fetchCouponActivityDetail = (id: number) => {
      return request<any>({
        url: `/v1/coupon/activity/${id}`,
        method: 'GET',
      });
    };

    /**
     * 创建优惠券活动
     * @param data 活动信息
     * @returns
     */
    export const createCouponActivity = (data: any) => {
      return request<any>({
        url: '/v1/coupon/activity',
        method: 'POST',
        data,
      });
    };

    /**
     * 更新优惠券活动
     * @param id 活动ID
     * @param data 活动信息
     * @returns
     */
    export const updateCouponActivity = (id: number, data: any) => {
      return request<any>({
        url: `/v1/coupon/activity/${id}`,
        method: 'PUT',
        data,
      });
    };

    /**
     * 更新活动状态
     * @param id 活动ID
     * @param status 状态
     * @returns
     */
    export const updateActivityStatus = (id: number, status: number) => {
      return request({
        url: `/v1/coupon/activity/${id}/status`,
        method: 'PUT',
        data: { status },
      });
    };

    /**
     * 删除优惠券活动
     * @param id 活动ID
     * @returns
     */
    export const deleteCouponActivity = (id: number) => {
      return request({
        url: `/v1/coupon/activity/${id}`,
        method: 'DELETE',
      });
    };

    // ==================== 优惠券核销相关接口 ====================

    /**
     * 获取核销记录列表
     * @param params 查询参数
     * @returns
     */
    export const fetchVerifyRecords = (params: any) => {
      return request<any>({
        url: '/v1/coupon/verify',
        method: 'GET',
        data: params,
      });
    };

    /**
     * 扫码核销优惠券
     * @param code 优惠券码
     * @returns
     */
    export const verifyCouponByCode = (code: string) => {
      return request<any>({
        url: '/v1/coupon/verify/scan',
        method: 'POST',
        data: { code },
      });
    };

    /**
     * 手动核销优惠券
     * @param couponId 优惠券ID
     * @param data 核销信息
     * @returns
     */
    export const verifyCouponManual = (couponId: number, data: any) => {
      return request<any>({
        url: `/v1/coupon/verify/manual`,
        method: 'POST',
        data: { coupon_id: couponId, ...data },
      });
    };

    /**
     * 获取核销详情
     * @param id 核销记录ID
     * @returns
     */
    export const fetchVerifyDetail = (id: number) => {
      return request<any>({
        url: `/v1/coupon/verify/${id}`,
        method: 'GET',
      });
    };

    // ==================== 优惠券统计相关接口 ====================

    /**
     * 获取优惠券统计数据
     * @param params 查询参数
     * @returns
     */
    export const fetchCouponStatistics = (params: any) => {
      return request<any>({
        url: '/v1/coupon/statistics',
        method: 'GET',
        data: params,
      });
    };

    /**
     * 获取活动统计数据
     * @param activityId 活动ID
     * @returns
     */
    export const fetchActivityStatistics = (activityId: number) => {
      return request<any>({
        url: `/v1/coupon/activity/${activityId}/statistics`,
        method: 'GET',
      });
    };

    // ==================== 批量操作相关接口 ====================

    /**
     * 批量更新优惠券状态
     * @param couponIds 优惠券ID数组
     * @param status 状态
     * @returns
     */
    export const batchUpdateCouponStatus = (couponIds: number[], status: number) => {
      return request({
        url: '/v1/coupon/batch/status',
        method: 'PUT',
        data: { coupon_ids: couponIds, status },
      });
    };

    /**
     * 批量删除优惠券
     * @param couponIds 优惠券ID数组
     * @returns
     */
    export const batchDeleteCoupons = (couponIds: number[]) => {
      return request({
        url: '/v1/coupon/batch/delete',
        method: 'DELETE',
        data: { coupon_ids: couponIds },
      });
    };

    /**
     * 批量导出优惠券
     * @param couponIds 优惠券ID数组
     * @returns
     */
    export const batchExportCoupons = (couponIds: number[]) => {
      return request({
        url: '/v1/coupon/batch/export',
        method: 'POST',
        data: { coupon_ids: couponIds },
      });
    };

    /**
     * 优惠券数据导入
     * @param file 文件
     * @returns
     */
    export const importCoupons = (file: any) => {
      return request({
        url: '/v1/coupon/import',
        method: 'POST',
        data: file,
      });
    };
